package com.ruoyi.publish.service.impl;

import com.ruoyi.publish.domain.RecommendArticle;
import com.ruoyi.publish.mapper.RecommendArticleMapper;
import com.ruoyi.publish.service.RecommendArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RecommendArticleServiceImpl implements RecommendArticleService {
    @Autowired
    private RecommendArticleMapper recommendArticleMapper;
    @Override
    public int insert(RecommendArticle recommendArticle) {
        // 1. 校验：同一栏目下（recommendId）是否已存在该文章（articleId）
        int count = recommendArticleMapper.countByRecommendIdAndArticleId(
                recommendArticle.getRecommendId(),
                recommendArticle.getArticleId()
        );
        if(count>0){
            System.out.println("该文章已在推荐列表中，请勿重复添加");
        }


        return recommendArticleMapper.insert(recommendArticle);
    }

    @Override
    public List<RecommendArticle> select(Long recommendArticleId) {
        return recommendArticleMapper.select(recommendArticleId);
    }

    @Override
    public int delete(long recommendArticleId) {
        return recommendArticleMapper.delete(recommendArticleId);
    }

    @Override
    public int update(RecommendArticle recommendArticle) {
        return recommendArticleMapper.update(recommendArticle);
    }

    @Override
    public List<RecommendArticle> selectAllArticles(List<Long> columnIdList, List<Long> excludeArticleId, String startDate, String endDate, boolean excludeRecommended) {
        return recommendArticleMapper.selectAllArticles(columnIdList,excludeArticleId,startDate,endDate,excludeRecommended);
    }
}
